#include "reg52.h"
#include "main.h"
#include "bsp_key.h"

#define u8 unsigned char
#define u32 unsigned int

void Control();

#define GPIO_LED P0

u8 ledValue = 0xfe;
u8 flickerFlag = 0;

void main()
{
	u8 i;
	while(1)
	{
		GPIO_LED = ledValue;
		
		for(i = 10; i > 0; i--)
		{
			Control();
			delay_ms(10);
		}
		
		if(flickerFlag)
		{
			GPIO_LED = 0xff;
			
			for(i = 10; i > 0; i--)
			{
				Control();
				delay_ms(10);
			}
		}
	}
}

void Control()
{
	u8 keyNum = Key_Scan();
	switch(keyNum)
	{
	case (0xfe):
		if(ledValue != 0xfe)
		{
			ledValue = ~((~ledValue) >> 1);
		}
		break;
	case (0xfd):
		flickerFlag = ~flickerFlag;
		break;
	case (0xfb):
		if(ledValue != 0x7f)
		{
			ledValue = ~((~ledValue) << 1);
		}
		break;
	default:
		break;
	}
}
